<template>
<div class="ticketadd">
	<ul>
		<div style="font-size:30px;margin:0px 0px 20px 80px;">添加车票</div>
		<hr style="width:280px; margin-left:0px;">
		<li style="margin-bottom:10px;">
			<select name="出发地" style="width:280px;height:30px;" v-model="ticket.start">
				<option v-for="c in city">{{c}}</option>
			</select>
		</li>
		<li style="margin-bottom:10px;">
			<select name="到达地" style="width:280px;height:30px;" v-model="ticket.end">
				<option v-for="t in city">{{t}}</option>
			</select>
		</li>
		<li><input type="date" placeholder="出发时间" v-model="ticket.startTime"></li>
		<li style="margin-bottom:10px;">
			<select name="车票类型" style="width:280px;height:30px;" v-model="ticket.ticketType">
				<option>一等座</option>
				<option>二等座</option>
				<option>三等座</option>
			</select>
		</li>
		<li><input type="text" placeholder="车票数目" v-model="ticket.ticketSum"></li>
		<li><input type="text" placeholder="车票价格" v-model="ticket.ticketPrice"></li>
		<li><input type="button" value="添加" @click="addTicket()"></li>
	</ul>
</div>
</template>
 
<script>
module.exports = {
    data: function() {
        return {
        	ticket : {
	        	start : '',
	        	end : '',
	        	startTime : '',
	        	ticketType : '',
	        	ticketSum : '',
	        	ticketPrice : ''
        	},
        	city : {
        		1:'青岛',
        		2:'潍坊',
        		3:'淄博',
        		4:'枣庄',
        		5:'东营',
        		6:'烟台',
        		7:'济宁',
        		8:'泰安',
        		9:'威海',
        		10:'日照',
        		11:'临沂',
        		12:'德州',
        		13:'聊城',
        		14:'滨州',
        		15:'菏泽',
        		16:'蓬莱',
        		17:'高密',
        		18:'胶州'
        		},
        	sp : 1
        }
    },
    mounted : function(){
    	if(this.$route.query.sp){
    		this.sp = this.$route.query.sp;
    	}
    },
    methods : {
    	addTicket : function(){
    		
    		if(this.ticket.start == this.ticket.end){
    			alert("出发地与到达地不能一致！")
    			return;
    		}
    		if(this.ticket.start=='' ||this.ticket.end=='' ||this.ticket.startTime==''
    		|| this.ticket.ticketType=='' ||this.ticket.ticketSum=='' ||this.ticket.ticketPrice==''){
    			alert("请完善好车票信息");
    			return;
    		}
    		var target = this;
    		axios.post('/bac/ticket/insertTicket',this.ticket)
    		.then(function(response){
    			var sc = response.data.success;
    			if(sc==true){
    				alert("添加成功！")
    				target.$router.push({path:'/ticketController',query:{sp:target.sp}});
    			}
    		})
    		.catch(function(error){
    			console.log(error);
    		});
    	}
    }
}
</script>
 
<style>
	body,ul,li,a{
		list-style:none;
		text-decoration:none;
		padding:0px;
		margin:0px;
	}
	.ticketadd{
		background-color:#4682B4;
		width:auto;
		min-height:500px;
		height:auto;
		margin-top:120px;
		padding:80px 0px 0px 600px;
		border:10px double #FFFFFF;
	}
	.ticketadd ul li input{
		width:280px;
		height:35px;
		margin-bottom:10px;
		padding-left:10px;
	}
</style>